﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using VK.Comm;
using VK.Comm.TransactSql;
using VK.Casemeet.TravelLogs;
using VK.Casemeet.Employees;
using VK.Casemeet.Merchants;

namespace VK.Casemeet.Web.ShopAdmin.TravelLogs
{
    public partial class TravelLogList : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            (this.Master as Site).SiteMapPathControl.MapPathList = new List<MapPath>(){
                new MapPath{ Text="桌面",Url="/ShopAdmin/Home.aspx"},
                new MapPath{ Text="游记日志",Url="#"}
            };

            if (!IsPostBack)
            {
                LoadData(false);
            }
        }

        protected void LoadData(bool isCondition)
        {
            IList<Condition> conditionlst = new List<Condition>();
            conditionlst.Add(new Condition { TableName = "TravelLog", FieldName = "ObjectID", ConditionType = ConditionType.NumeralEqual, ConditionValue = AdminBLL.GetSessionAdmin().ShopID, DbType = DbType.Int32 });
            conditionlst.Add(new Condition { TableName = "TravelLog", FieldName = "ObjectType", ConditionType = ConditionType.NumeralEqual, ConditionValue = 1, DbType = DbType.Int32 });
            if (isCondition)
            {
                conditionlst.Add(new Condition { TableName = "TravelLog", FieldName = "Title", ConditionType = ConditionType.TextLIKE, ConditionValue = txtTitle.Text.Trim(), DbType = DbType.String });
            }
            aspNetPager.RecordCount = TravelLogBLL.GetTravelLogCount(conditionlst);
            rptTravelLog.DataSource = TravelLogBLL.GetTravelLogList(aspNetPager.StartRecordIndex, aspNetPager.EndRecordIndex, conditionlst, string.Empty, SortMode.Desc);
            rptTravelLog.DataBind();
        }

        protected void butSearch_Click(object sender, EventArgs e)
        {
            LoadData(true);
        }

        protected void aspNetPager_PageChanged(object sender, EventArgs e)
        {
            LoadData(true);
        }

        protected void rptTravelLog_ItemCommand(object source, RepeaterCommandEventArgs e)
        {
            if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
            {
                switch (e.CommandName)
                {
                    case "Delete":
                        if (TravelLogBLL.DeleteTravelLog(int.Parse(e.CommandArgument.ToString())) > 0)
                        {
                            Message.Msg(this.Page, CS.MsgDelSuccess, MessageType.Success);
                        }
                        else
                        {
                            Message.Msg(this.Page, CS.MsgDelFailure, MessageType.Failure);
                        }
                        break;
                }
                LoadData(true);
            }
        }
    }
}